home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte26 / ex3.c < prev    next >
C/C++ Source or Header  |  1995-06-03  |  2KB  |  55 lines

  1. #include <genstub.c>
  2.  
  3. #define OUR_ERROR 0x10000000
  4.  
  5. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.    static UINT uClicks;
  8.    static UINT uRow;
  9.    switch (uMsg)
  10.    {
  11.          case WM_CREATE:
  12.                uRow = 0;
  13.                uClicks = 0;
  14.                return DefWindowProc( hWnd, uMsg, wParam, lParam);
  15.          case WM_DESTROY:
  16.                PostQuitMessage( 0 );
  17.                break;
  18.          case WM_COMMAND:
  19.                switch ( LOWORD( wParam ) )
  20.                {
  21.                      case IDM_TEST:
  22.                      {
  23.                            HANDLE hModule;
  24.                            char szBuffer[128];
  25.                            HDC hDC = GetDC(hWnd);
  26.                            // Turn off the DLL not found error mode.
  27.                            UINT uOldMode = SetErrorMode( SEM_NOOPENFILEERRORBOX );
  28.                            if ( (hModule = LoadLibrary("EX4.DLL")) )
  29.                            {
  30.                               // Get address of external function.
  31.                               FARPROC lpfnSetErrorCondition;
  32.                               lpfnSetErrorCondition =
  33.                                     GetProcAddress(hModule, "SetTheErrorCondition");
  34.                               // Call external function to change error code.
  35.                               if (lpfnSetErrorCondition)
  36.                                  (*lpfnSetErrorCondition) (OUR_ERROR + uClicks++);
  37.                            }
  38.                            TextOut( hDC, 0, 16 * uRow++, szBuffer,
  39.                                     wsprintf(szBuffer,"Error code is: %X",
  40.                                     GetLastError() ));
  41.                            SetErrorMode( uOldMode );
  42.                            ReleaseDC(hWnd, hDC);
  43.                      }
  44.                      break;
  45.                      case IDM_EXIT:
  46.                            DestroyWindow( hWnd );
  47.                            break;
  48.                }
  49.                break;
  50.          default:
  51.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  52.    }
  53.    return (NULL);
  54. }
  55.